/**
 * Created by mac on 16/6/29.
 */
var sqlite3 = require('sqlite3').verbose();
//var db = new sqlite3.Database(':memory:');
var openCb = function (error){ 
	if(!error){
		console.log("open db succeed!") 
	}
}
var db = new sqlite3.Database('haha.db', openCb );
db.serialize(function() {
    db.run('CREATE TABLE IF NOT EXISTS infos (id INTEGER PRIMARY KEY AUTOINCREMENT,ip TEXT,path TEXT,time INTEGER)  ');
    var stmt = db.prepare('INSERT INTO infos (ip,path,time)  VALUES (?,?,?)');
    for (var i = 0; i < 5; i++) {
        stmt.run('ip ' + i,"path"+i,new Date().getTime());
    }
    stmt.finalize();
    db.each('SELECT * FROM infos', function(err, row) {
        console.log(row.ip + ': ' + row.path + ': ' + row.time);
    });
});

db.close(function (error){ 
	if(!error){
		console.log("close db succeed!") 
	}
});